﻿using System;
using System.Collections.Generic;

using DflyingForum.Core.Data.NHHelper;

namespace DflyingForum.Core.Repositories
{
    /// <summary>
    ///  仓储
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    /// <typeparam name="TKey"></typeparam>
    interface IRepository<TEntity, TKey> where TEntity : class
    {

        /// <summary>
        /// 保存实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        TKey Save(TEntity entity);

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity"></param>
        void Update(TEntity entity);

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity"></param>
        void Delete(TEntity entity);

        TEntity FindBy(TKey id);

        /// <summary>
        /// 根据查询条件返回列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        IList<TEntity> FindBy(IList<CriteriaParameter> query);

        /// <summary>
        /// Lambda表达式返回列表
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        IList<TEntity> FindBy(Func<TEntity, bool> expression);

        /// <summary>
        ///  返回分页后的列表
        /// </summary>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="recordCount">总记录数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        IList<TEntity> FindByPage(int currentPage, int pageSize, out int recordCount, IList<CriteriaParameter> query);
    }
}
